package com.wsx.carrot.mybatis;

import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import com.wsx.carrot.druid.DruidConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * dao扫描路径，规范化的dao配置管理
 * Created by wangshuaixin on 17/9/8.
 */
@Component
@MapperScan(basePackages = {"com.wsx.carrot.*.dao","com.wsx.carrot.modular.*.dao"})
public class MybatisPlusConfig {

    @Autowired
    private DruidConfig druidConfig;

    /**
     * 分页插件
     * @return
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        paginationInterceptor.setDynamicDataSource(true);
        return paginationInterceptor;
    }

    /**
     * druid的初始化动作，需要制定初始方法
     * @return
     */
    @Bean(initMethod = "init")
    public DruidDataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        druidConfig.coinfig(dataSource);
        return dataSource;
    }
}
